﻿using AutoMapper;
using MediatR;
using WeekWork929.Api.Write.Appliaction.Commond;
using WeekWork929.Domain;
using WeekWork929.ErrorCode;
using WeekWork929.infrastrunceture;

namespace WeekWork929.Api.Write.Appliaction.CommondHandler
{
    public class UpdateCommondHandler : IRequestHandler<UpdateCommond, ApiResult<int>>
    {
        private readonly IBaseIRepository<Workmend> workMed;
        private readonly IMapper mapper;

        public UpdateCommondHandler(IBaseIRepository<Workmend> workMed, IMapper mapper)
        {
            this.workMed = workMed;
            this.mapper = mapper;
        }
        public async Task<ApiResult<int>> Handle(UpdateCommond request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ApiEnum.修改成功;
            result.Msg=ApiEnum.修改成功.ToString();
            Workmend workmend= mapper.Map<Workmend>(request);
            await workMed.Update(workmend);
            return await Task.FromResult(result);
        }
    }
}
